package demoMod.invincibleOne.cards.invincible;

import basemod.BaseMod;
import basemod.helpers.CardModifierManager;
import basemod.interfaces.OnPlayerTurnStartSubscriber;
import com.megacrit.cardcrawl.actions.GameActionManager;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.cards.status.Dazed;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.patches.PreDrawPatch;
import demoMod.invincibleOne.relics.TaskGoal;

public class LavaGround extends AbstractInvincibleCard implements OnPlayerTurnStartSubscriber, PreDrawPatch.ICardPreDraw {
    public static final String ID = InvincibleOneMod.makeID("LavaGround");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/LavaGround.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.SELF;

    private static final int COST = -2;

    public LavaGround() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        this.baseMagicNumber = this.magicNumber = 1;
        CardModifierManager.addModifier(this, modifier);
        this.tags.add(CardTagsEnum.ALERT);
        this.cardsToPreview = new Dazed();
    }

    @Override
    public boolean onBattleStart() {
        BaseMod.unsubscribe(this);
        BaseMod.subscribe(this);
        return true;
    }

    @Override
    public void onRemoveFromMasterDeck() {
        super.onRemoveFromMasterDeck();
        BaseMod.unsubscribeLater(this);
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeMagicNumber(1);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    @Override
    public void onPreDraw() {
        addToBot(new MakeTempCardInHandAction(this.cardsToPreview, this.magicNumber));
    }

    @Override
    public void receiveOnPlayerTurnStart() {
        if (!AbstractDungeon.player.masterDeck.contains(this)) {
            BaseMod.unsubscribeLater(this);
            return;
        }
        if (TaskGoal.combatTurn > 0) {
            addToBot(new MakeTempCardInHandAction(this.cardsToPreview, this.magicNumber));
        }
    }
}
